package com.single.weblearn.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.transaction.annotation.Transactional;

import com.single.weblearn.meta.User;

public interface UserDao {
	@Results({ 
		@Result(property = "id", column = "id"),
		@Result(property = "userName", column = "userName"),
		@Result(property = "password", column = "password"),
		@Result(property = "nickName", column = "nickName"),
		@Result(property = "userType", column = "userType")
        }
	)
	@Transactional
	@Select("select * from person where userName =#{userName}")
	 public User getUserByname(String userName);
	
	@Select("select password from person where userName =#{userName}")
	 public String valiateUser(String userName);
	
	@Results({
		@Result(property = "id", column = "id"),
		@Result(property = "userName", column = "userName"),
		@Result(property = "password", column = "password"),
		@Result(property = "nickName", column = "nickName"),
		@Result(property = "userType", column = "userType")
        }
	)
	@Transactional
	@Select("select * from person where id =#{id}")
	 public User getUserById(Integer id);
	
	@Transactional
	@Insert("insert into person (userName,password,nickName,userType)  values(#{userName},#{password},#{nickName},#{userType})")
	public void addUser(User user);
	
	@Transactional
	@Update("update person set nickName =#{nickName},password=#{password}  where userId = #{userId}")
	public void updateUser(User user);
	
}
